import { Directive, ElementRef, Input, HostListener } from '@angular/core';
import { DataTransmissionService } from '../services/data-transmission.service'
import {WindowEventService} from '../services/window.event.service'
import {XYDistance} from '../data_model/data-model'

//setting tree 的按键事件
@Directive({ selector: 'div[id="SettingTree"]' })
export class settingTreeContextmenuDirective {
  constructor(private dataTransmissionService: DataTransmissionService) {

  }
  //按键事件
  @HostListener('contextmenu', ['$event'])
  onContextmenu(ev: MouseEvent) {
    this.dataTransmissionService.sendSettingTreeContextMenuSubject(ev);
    ev.preventDefault();
  }
}

//window risize
@Directive({ selector: 'body' })
export class MapResizeDirective {
  constructor(private dataTransmissionService: DataTransmissionService) { }

  //resize
  @HostListener('window:resize', ['$event.target'])
  onResize(ev: Window) {
    this.dataTransmissionService.sendMapResizeSubject(ev);
  }
}

//dialog drag
@Directive({selector:'.modal'})
export class DialogDragDirective{
  private MousePressed:boolean = false;
  private OriginalPoint:XYDistance;
  constructor(private windowEventService:WindowEventService){}

  //onMousePress
  @HostListener('mousedown',['$event'])
  onmousedown(ev:MouseEvent){
    this.windowEventService.sendDialogMousePressedSubject(true);
    this.MousePressed = true;
    this.OriginalPoint = new XYDistance(ev.x,ev.y);
  }
  @HostListener('mouseup',['$event'])
  onmouseup(){
    this.windowEventService.sendDialogMousePressedSubject(false);
    this.MousePressed = false;
  }
  //onMouseMove
  @HostListener('mousemove',['$event'])
  onMousemove(ev:MouseEvent){
    if(this.MousePressed){
  
      this.windowEventService.sendDialogMouseMovedSubject(new XYDistance(ev.x-this.OriginalPoint.DistanceX,ev.y-this.OriginalPoint.DistanceY));
    }
  }

}

